package com.zzyl.nursing.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.zzyl.nursing.vo.NursingProjectVo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.zzyl.common.annotation.Log;
import com.zzyl.common.core.controller.BaseController;
import com.zzyl.common.core.domain.AjaxResult;
import com.zzyl.common.enums.BusinessType;
import com.zzyl.nursing.domain.NursingProject;
import com.zzyl.nursing.service.INursingProjectService;
import com.zzyl.common.utils.poi.ExcelUtil;
import com.zzyl.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;

/**
 * 护理项目Controller
 * 处理护理项目的查询、新增、修改、删除等操作
 *
 * @author zmc
 * @date 2025-10-07
 */
@Api(tags = "护理项目管理", description = "护理项目相关的CRUD操作及数据导出功能")
@RestController
@RequestMapping("/nursing/project")
public class NursingProjectController extends BaseController
{
    @Autowired
    private INursingProjectService nursingProjectService;

    /**
     * 查询护理项目列表（分页）
     */
    @ApiOperation(value = "查询护理项目列表（分页）", notes = "根据条件分页查询护理项目信息，支持多条件筛选")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "nursingProject", value = "护理项目查询条件对象",
                    dataTypeClass = NursingProject.class, paramType = "query")
    })
    @PreAuthorize("@ss.hasPermi('nursing:project:list')")
    @GetMapping("/list")
    public TableDataInfo list(
            @ApiParam(value = "护理项目查询条件，包含名称、状态等筛选字段", required = false)
            NursingProject nursingProject
    )
    {
        startPage();
        List<NursingProject> list = nursingProjectService.selectNursingProjectList(nursingProject);
        return getDataTable(list);
    }

    /**
     * 查询所有护理项目列表（不分页）
     */
    @ApiOperation(value = "查询所有护理项目列表（不分页）", notes = "获取系统中所有的护理项目信息，返回完整列表")
    @GetMapping("/all")
    public AjaxResult listAll()
    {
        List<NursingProjectVo> list = nursingProjectService.selectAll();
        return success(list);
    }

    /**
     * 导出护理项目列表
     */
    @ApiOperation(value = "导出护理项目列表", notes = "根据筛选条件将符合条件的护理项目数据导出为Excel文件")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "response", value = "HTTP响应对象，用于输出Excel文件流",
                    dataTypeClass = HttpServletResponse.class, paramType = "query", required = true),
            @ApiImplicitParam(name = "nursingProject", value = "护理项目查询条件，用于筛选导出数据",
                    dataTypeClass = NursingProject.class, paramType = "query")
    })
    @PreAuthorize("@ss.hasPermi('nursing:project:export')")
    @Log(title = "护理项目", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(
            @ApiParam(value = "HTTP响应对象，用于输出Excel文件", required = true)
            HttpServletResponse response,
            @ApiParam(value = "护理项目筛选条件，为空时导出全部数据", required = false)
            NursingProject nursingProject
    )
    {
        List<NursingProject> list = nursingProjectService.selectNursingProjectList(nursingProject);
        ExcelUtil<NursingProject> util = new ExcelUtil<NursingProject>(NursingProject.class);
        util.exportExcel(response, list, "护理项目数据");
    }

    /**
     * 获取护理项目详细信息
     */
    @ApiOperation(value = "获取护理项目详细信息", notes = "根据护理项目ID查询单个项目的完整信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "护理项目ID",
                    dataTypeClass = Long.class, paramType = "path", required = true)
    })
    @PreAuthorize("@ss.hasPermi('nursing:project:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(
            @ApiParam(value = "护理项目唯一标识ID", required = true, example = "1001")
            @PathVariable("id") Long id
    )
    {
        return success(nursingProjectService.selectNursingProjectById(id));
    }

    /**
     * 新增护理项目
     */
    @ApiOperation(value = "新增护理项目", notes = "创建新的护理项目，需传入完整的项目信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "nursingProject", value = "护理项目对象，包含所有必要的创建信息",
                    dataTypeClass = NursingProject.class, paramType = "body", required = true)
    })
    @PreAuthorize("@ss.hasPermi('nursing:project:add')")
    @Log(title = "护理项目", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(
            @ApiParam(value = "护理项目信息，包含名称、描述、类型等必要字段", required = true)
            @RequestBody NursingProject nursingProject
    )
    {
        return toAjax(nursingProjectService.insertNursingProject(nursingProject));
    }

    /**
     * 修改护理项目
     */
    @ApiOperation(value = "修改护理项目", notes = "更新已存在的护理项目信息，需包含项目ID")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "nursingProject", value = "护理项目对象，包含ID和要更新的字段",
                    dataTypeClass = NursingProject.class, paramType = "body", required = true)
    })
    @PreAuthorize("@ss.hasPermi('nursing:project:edit')")
    @Log(title = "护理项目", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(
            @ApiParam(value = "护理项目信息，必须包含ID和要修改的字段", required = true)
            @RequestBody NursingProject nursingProject
    )
    {
        return toAjax(nursingProjectService.updateNursingProject(nursingProject));
    }

    /**
     * 删除护理项目
     */
    @ApiOperation(value = "删除护理项目", notes = "根据ID数组批量删除护理项目，支持单次删除多个项目")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "ids", value = "护理项目ID数组",
                    dataTypeClass = Long[].class, paramType = "path", required = true)
    })
    @PreAuthorize("@ss.hasPermi('nursing:project:remove')")
    @Log(title = "护理项目", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(
            @ApiParam(value = "护理项目ID数组，多个ID用逗号分隔", required = true, example = "1001,1002")
            @PathVariable Long[] ids
    )
    {
        return toAjax(nursingProjectService.deleteNursingProjectByIds(ids));
    }
}
